<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios错误处理</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <button>注册</button>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script>
        document.querySelector('button').addEventListener('click', () => {
            axios({
                url: 'http://hmajax.itheima.net/api/register',
                method: 'POST',
                data: {
                    username: 'NingChe210307',
                    password: '123456'
                }
            })
                .then(result => console.log(result))
                .catch(error => alert(error.response.data.message))
        })
    </script>
</body>

</html>